//
//  DmTVC.m
//  tableViewDemo
//
//  Created by lix on 16/8/25.
//  Copyright © 2016年 lix. All rights reserved.
//

#import "DMTVC.h"

@implementation DMTVC

@synthesize cellHeight = _cellHeight;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //分配内存
        UILabel * label = [[UILabel alloc]init];
        _label = label;
        
    }
    return self;
}
//返回高度
- (CGFloat)cellHeight
{
    //  强制布局之前，需要先手动设置下cell的真实宽度，以便于准确计算
    CGRect rect = self.frame;
    rect.size.width = [[UIScreen mainScreen] bounds].size.width;
    self.frame = rect;
    [self layoutIfNeeded];    //  一定要强制布局下，否则拿到的高度不准确
    return CGRectGetMaxY(self.label.frame);
    
}

- (void)setTextForLabel:(NSString *)text{
    
    _label.frame = CGRectMake(10, 10, self.frame.size.width, 0);
    _label.text = text;
    _label.lineBreakMode = UILineBreakModeWordWrap;
    _label.numberOfLines = 0;
    [self addSubview:_label];
    [_label sizeToFit];
    
    _cellHeight = [self cellHeight];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    
}

@end
